//
//  MHIdentityConfigViewController.m
//  MiaoCircle
//
//  Created by 许正荣 on 2018/7/26.
//  Copyright © 2018年 acgera. All rights reserved.
//

#import "MHIdentityConfigViewController.h"
#import "MHIdentityViewModel.h"
#import "MHAlertMessageView.h"

@interface MHIdentityConfigViewController ()
@property (weak, nonatomic) IBOutlet UILabel *tipsLabel;
@property (weak, nonatomic) IBOutlet UILabel *nameLabel;
@property (weak, nonatomic) IBOutlet UILabel *identityLable;
@property (weak, nonatomic) IBOutlet UITextField *nameTextField;
@property (weak, nonatomic) IBOutlet UITextField *identityCardTextFeild;
@property (weak, nonatomic) IBOutlet UIButton *submitBtn;
@property(nonatomic, strong)  MHIdentityViewModel *viewModel;

@end

@implementation MHIdentityConfigViewController
@dynamic viewModel;
- (void)viewDidLoad {
    [super viewDidLoad];
    self.tipsLabel.font = MHRegularFont_14;
    self.nameLabel.font = MHRegularFont_14;
    self.identityLable.font = MHRegularFont_14;
    self.nameTextField.font = MHRegularFont_14;
     self.identityCardTextFeild.font = MHRegularFont_14;
    self.submitBtn.titleLabel.font = MHRegularFont_15;
    @weakify(self);
    [self.submitBtn bk_whenTapped:^{
        [self.view endEditing:YES];
        self.zh_popupController = [zhPopupController new];
        MHAlertMessageView *alert = [[MHAlertMessageView alloc] initWihtTitle:@"" message:@"请仔细检查你的资料，认证失败将无法提现"];
        alert.mh_width = self.view.mh_width * 0.8;
        __weak __typeof(self)weakSelf = self;
        [alert.dissMissButton setTitle:@"取消" forState:0];
        [alert.comfirmButton setTitle:@"确定" forState:0];
        [alert.dissMissButton bk_whenTapped:^{
            [weakSelf.zh_popupController dismiss];
        }];
        [alert.comfirmButton bk_whenTapped:^{
            @strongify(self);
            if (self.nameTextField.text.length <= 0) {
                [MBProgressHUD mh_showTips:@"姓名不能为空"];
                return ;
            }
            if (self.identityCardTextFeild.text.length <= 0) {
                [MBProgressHUD mh_showTips:@"身份证号为空"];
                return ;
            }
            @weakify(self);
            [[self.viewModel.services.client addWeiXinPayAccountWith:self.nameTextField.text idCard:self.identityCardTextFeild.text] subscribeNext:^(id x) {
                @strongify(self);
                [[self.viewModel.services.client addCashDetailWithAmount:self.viewModel.tixianAmount] subscribeNext:^(MHHTTPResponse *respose) {
                    [MHNotificationCenter postNotificationName:MHTiXianSuccessNotification object:respose];
                    
                    [self.viewModel.services popViewModelAnimated:YES];
                } completed:^{
                    
                }];
            }];
            
            [weakSelf.zh_popupController dismiss];
        }];
        [self.zh_popupController presentContentView:alert duration:0.25 springAnimated:YES];
        
     
    }];

    // Do any additional setup after loading the view from its nib.
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
